In this tutorial I will show you how to create custom 404 error page for a Django project.
Creating a custom 404 page provides a user-friendly informative message when a page is not found. Instead of a "Page Not Found" message, show your custom 404 page.
Solution:
1.Ensure that Django project is configured to use custom error pages by setting DEBUG = False in settings.py.
2.In templates directory, create a file named 404.html.
Example 404 Page:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Not Found</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin: 50px; } h1 { font-size: 3em; color: #ff6f61; } p { font-size: 1.5em; } a { color: #007bff; text-decoration: none; } a:hover { text-decoration: underline; } </style> </head> <body> <h1>404 - Page Not Found</h1> <p>Sorry, the page you are looking for does not exist.</p> <a href="/">Return to Home</a> </body> </html>
VIDEO GUIDE:
Post your comments / questions
Recent Article
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
Related Article